<?php


// 处理字符串防止特殊符号引起的错误，
$process_include    = array('title', 'url');
string_pre_process($record, $process_include);
extract($record, EXTR_OVERWRITE);



if($img != '') {
    $this_ad_url = $G_web_upload . $img;
}




$this_height = $height > $default_height ? $default_height : $height;

if($height == 0 || $width == 0) {
    $this_height = $default_height;
    $this_width  = $default_width;
    $height = $default_height;
    $width  = $default_width;
} else {
    if($height > $default_height) {
        $this_height = $default_height;
        $this_width  = ceil($default_height/$height) * $width;
    } else {
        $this_height = $height;
        $this_width  = $width;
    }
}



$chk_display    = $display == 1 ? 'checked' : '';


// 取得返回字符串
$back_url   = strcode(getcookie('back_url'), 'DECODE');
if($back_url == '') $back_url   = $mod_url['li'];



if($action == 'modify') {
    $txt_form_title = "修改广告";
    $cur_tab_menu   = "not_exist";
} else {
    $txt_form_title = "新增广告";
    $cur_tab_menu   = "admin_add";
}

require($abs_admin_cppath . '/header.php');
?>
<SCRIPT LANGUAGE="JavaScript" SRC="<?php echo $url_global['common']; ?>/js/Validator.js"></SCRIPT>
<div class="spH10"></div>




	<div class="datacontainer2" style="width:600px;">
<div class="header">
	&nbsp;&nbsp;<span class="font_form_head"><?php echo $txt_form_title ?></span>
</div>
<table BORDER="0" cellpadding="0" cellspacing="0" width="100%" class="list_table">
<form action="<?php echo $mod_url['save'] ?>" method="post" name="user_data" enctype="multipart/form-data" onsubmit="return Validator.Validate(this,3);">
<TR>
	<TD width="120" align="right" class="caption">广告位置：</TD>
	<TD class="FormCell">
<SCRIPT LANGUAGE="JavaScript">
<!--
var adpos   = <?php echo js_pagepos($ad_position) ?>;



function pagepos_change(o, id) {
    var key = o.options[o.selectedIndex].value;
    var opt = GE(id);
    option_remove(id);
    if(key == '') return false;

    var arr = adpos[key];
    for(var i=0; i < arr.length; i++) {
        var items   = new Option(arr[i][1],arr[i][0]);
        items.width = arr[i][2];
        items.height= arr[i][3];
        opt.options.add(items);
        
    }
}
function pos_change(o) {
    var item = o.options[o.selectedIndex];
    var form = o.form;

    form.elements['ad[width]'].value    = item.width;
    form.elements['ad[height]'].value   = item.height;
}
function pos_inti(pos) {
    var o = GE('pagepos');
    pagepos_change(o, 'pos');


    var opt = GE('pos');
    for(var i=0; i < opt.length; i++) {
        if(pos == opt.options[i].value) {
            opt.selectedIndex = i;
            break;
        }
    }
}
function option_remove(id) {
    var o   = GE(id);
    for(var i=o.length-1; i>0; i--) {
        o.options.remove(i);
    }
}
//-->
</SCRIPT>
		<select name="ad[pagepos]" id="pagepos" onchange="pagepos_change(this, 'pos')" class="select01">
		<?php echo pagepos_option($ad_position, $pagepos) ?>
		</select>
		<span class="mustfill">*</span>


		<select name="ad[pos]" id="pos" onchange="pos_change(this)" class="select01">
		<option value="">不属于任何位置</option>
		</select>
<SCRIPT LANGUAGE="JavaScript">
<!--
pos_inti('<?php echo $pos?>');
//-->
</SCRIPT>
	</TD>
</TR>
<TR>
	<TD width="120" align="right" class="caption">广告标题：</TD>
	<TD class="FormCell">
		<input type="text" name="ad[title]" value="<?php echo $title ?>" class="text" size="40"
		dataType="Require" msg="“广告标题”必须填写">
		<span class="mustfill">*</span>
	</TD>
</TR>
<TR>
	<TD width="120" align="right" class="caption">链接到：</TD>
	<TD class="FormCell">
		<input type="text" name="ad[url]" value="<?php echo $url ?>" class="text" size="40"> 请加上http://
	</TD>
</TR>

<TR>
	<TD width="120" align="right" class="caption">上传图片文件：</TD>
	<TD class="FormCell">

<TABLE border="0" cellpadding="0" cellspacing="0" class="none_border">
<TR>
	<TD height="80"><a href="<?php echo $this_ad_url ?>" target="_blank"><img src="<?php echo $this_ad_url ?>" id="obj_thumb_img" width="435" border="0"></a></TD>
</TR>
<TR>
	<TD>

<input type="file" name="img" class="text" onchange="return file_img_onchange(this, 'obj_thumb_img');"> 
<INPUT TYPE="checkbox" NAME="ad[delimg]" id="delimg" value="1"> <label for="delimg">删除图片</label>
<br />
图片宽度：
<input type="text" name="ad[width]" size="3" value="<?php echo $width ?>"
				onkeydown="return non_num_filter();" 
				class="text"
				style="text-align:right;padding-right:2px;">&nbsp;&nbsp;
高度：
<input type="text" name="ad[height]" size="3" value="<?php echo $height ?>" 
				onkeydown="return non_num_filter();" 
				class="text"
				style="text-align:right;padding-right:2px;">
	</TD>
</TR>
</TABLE>



	</TD>
</TR>
<TR>
	<TD width="120" align="right" class="caption">是否显示：</TD>
	<TD class="FormCell"><INPUT TYPE="checkbox" NAME="ad[display]" id="display" value="1" <?php echo $chk_display?>> <label for="display">选择表示显示</label>
	</TD>
</TR>
<!--<TR>
	<TD width="120" align="right" class="caption">外部FLV或FLASH：</TD>
	<TD class="FormCell">
		<label>
		<input name="ad[is_movi]" type="checkbox" id="ad[is_movi]" value="1" />
		</label>	</TD>
</TR>-->
<TR>
	<TD class="FormCell" colspan="2" align="center">
		<input type="submit" value=" 保存 " class="btn">
		<input type="reset" value=" 重置 " class="btn">
		<input type="button" value=" 返回 " class="btn" onclick="location.href='<?php echo $back_url ?>'">
		<input type="hidden" name="ad[id]" value="<?php echo $id ?>">
		<input type="hidden" name="save" value="<?php echo $save_flag ?>">
	</TD>
</TR>
</form>
</TABLE>
	</div>
<?php
require($abs_admin_cppath . '/footer.php');
?>